define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/question/index',
                    add_url: 'order/question/add',
                    edit_url: 'order/question/edit',
                    del_url: 'order/question/del',
                    multi_url: 'order/question/multi',
                    table: 'shop_order',
                    ajax_url:{
                        btn_1:'order/question/flag_act?type=1',//1:插旗
                        btn_8:'order/question/edit?type=3',//1:编辑
                        btn_5:{data:{},url:"order/question/pass_order",fc:function(data){
                                return true;
                            }},//通过
                    },
                    btn_mall_window:{
                        btn_array:["确定","取消"],
                        btn_evn_array_length:2,
                        btn_evn_array: {
                            evn_1:function (index,layero) {
                                var frame = Layer.getChildFrame('html', index);
                                var form = $("form",frame);
                                var success = function () {
                                    table.bootstrapTable('refresh');
                                    Layer.close(index);
                                }
                                Fast.api.form_ajax_submit(form,success);
                            },
                            evn_2:function (index,layero) {
                                Layer.close(index);
                            }
                        },
                        area:['600px','300px']
                    }

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_sno', title: __('Order_sno')},
                        {field: 'r.username', title: __('Paike_username')},
                        {field: 'back_time', title: __('Back_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'task_sno', title: __('Task_sno'),operate:false},
                        {field: 'a.username', title: __('审核人'),operate:false},
                        {field: 'n.username', title: __('Ad_username'),operate:false},
                        {field: 'o.real_money', title: __('Real_money')},
                        {field: 'flag', title:__('Flag'),searchList: {
                                "1":__('未插旗'),
                                "2":__('已插旗')},
                                 formatter:function(value,row,index){
                                    var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                     if(value==undefined || value=="null"){
                                         value =   value
                                     }else{
                                         value = value.toString();
                                     }
                                     var index = keys.indexOf(value);
                                     value = value === null ? '' : value;
                                    var display = index > -1 ? this.searchList[value] : null;
                                    var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                    if (!display) {
                                        display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                    }
                                    var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                    return html;
                                }

                                },
                        {field: 'flag_remarks', title:__('Flag_remarks')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter:function(value,row,index) {

                                var table = this.table;
                                // 操作配置
                                var options = table ? table.bootstrapTable('getOptions') : {};
                                // 默认按钮组
                                var buttons = $.extend([], this.buttons || []);

                                buttons.push(
                                    {
                                        name: 'btn_1',
                                        text: row.flag == "1" ? __('插旗') : __('已插旗'),
                                        extend: 'data-toggle="tooltip" data-name="btn_1" data-title="插旗"',
                                        classname: 'btn btn-xs btn-success btn-magic btn-small-window'
                                    },
                                    {
                                        name: 'btn_2',
                                        text: "订单详情",
                                        extend: 'data-toggle="tooltip" data-title="详情"',
                                        classname: 'btn btn-xs btn-success btn-magic btn-editone '
                                    },{
                                        name: 'btn_5',
                                        text: "通过",
                                        extend: 'data-toggle="tooltip" data-name="btn_5" data-title="通过" ',
                                        classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    });

                                return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                            }
                        }
                    ]
                ]
            });



            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $(function(){
                //console.log($(".example2"))
                require(['img_css/easy-loading','img_css/hammer.min','img_css/jquery.mousewheel.min','img_css/zoom-marker'],function(){
                    // $('#zoom-marker-img').zoomMarker({
                    //     src: $('#zoom-marker-img').data("url"),
                    //     rate: 0.2,
                    //     width: 100,
                    //     max: 1000,
                    //     markers:[
                    //         //{src:"img/marker.svg", x:500, y:500}
                    //     ]
                    // });
                    $("img").each(function(){
                        console.log($(this).data("url"));
                        if($(this).data("url")!=undefined && $(this).data("url")!="") {
                            $(this).zoomMarker({
                                src: $(this).data("url"),
                                rate: 0.1,
                                min: 100,
                                width: 100,
                                max: 3000,
                                markers: [
                                    //{src:"img/marker.svg", x:500, y:500}
                                ],
                            });
                        }
                    });
                    // $('#zoom-marker-img-alt').zoomMarker({
                    //     src: $('#zoom-marker-img-alt').data("url"),
                    //     rate: 0.1,
                    //     min:100,
                    //     width: 100,
                    //     max: 3000,
                    //     markers:[
                    //         //{src:"img/marker.svg", x:500, y:500}
                    //     ]
                    //
                    //
                    // });
                })
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});